package org.bulu.project.web.controller;

import com.github.pagehelper.PageInfo;
import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.dto.CommentDTO;
import org.bulu.project.service.video.service.CommentService;
import org.bulu.project.system.model.dto.CommentContentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/addComment")
    public void addComment(@RequestBody CommentDTO commentDTO){
        commentService.addComment(commentDTO);
    }

    @PostMapping("/deleteComment")
    public void deleteComment(@RequestParam("id") Integer id,@RequestParam("uid") Integer uid,@RequestParam("isAdmin") boolean isAdmin){
        commentService.deleteComment(id, uid, isAdmin);
    }

    @GetMapping("/findAllComment")
    public Result<PageInfo> findAllComment(@RequestParam("vid") Integer vid, @RequestParam("sortChoose") Integer sortChoose, @RequestParam("currentCommentPage") Integer currentCommentPage){
        List<CommentContentDTO> comments = commentService.getAllComments(vid,sortChoose);
        PageInfo result =  commentService.findParent(comments, sortChoose,currentCommentPage);
        return Result.success(result);
    }

    @PostMapping("/likeOrDislikeComment")
    public void likeOrDislikeComment(@RequestParam("id") Integer id,@RequestParam("userId") Integer userId,@RequestParam("isLike") boolean isLike){
        commentService.likeOrDislikeComment(id, userId, isLike);
    }
}
